"""
后台查看生成订单用例
"""
import unittest
from common.base import get_driver
# 后台
from page.backstage_login_page import BackstageLogin
from page.backstage_home_page import BackstageHome
# 前台
from page.home_page import HomePage
from page.phone_type_page import PhoneTypePage
from page.n85_page import N85Page
from page.settle_accounts_page import SettleAccountPage
from page.log_in_to_buy_page import LogInToBuy
from page.add_page import AddPage
from page.submit_order import SubmitOrder
from page.finish_page import Finish
from page.user_center import UserCenter


class BackstageCheckOrder(unittest.TestCase):
    @classmethod
    def setUpClass(cls) -> None:
        # 打开前台浏览器
        driver = get_driver()
        cls.home = HomePage(driver)
        cls.phone_type_page = PhoneTypePage(driver)
        cls.n85 = N85Page(driver)
        cls.settle_accounts_page = SettleAccountPage(driver)
        cls.log_in_to_buy_page = LogInToBuy(driver)
        cls.add_page = AddPage(driver)
        cls.submit_order = SubmitOrder(driver)
        cls.finish_page = Finish(driver)
        cls.user_center = UserCenter(driver)
        # 访问前台网址
        cls.home.get('http://localhost:8080/ecshop/index.php')

    def test01_order_unpaid(self):
        # 操作前台页面,获取前台生成的订单号
        self.home.click_phone_type()
        self.phone_type_page.click_n85()
        self.n85.send_keys_number(2)
        self.n85.click_bluetooth_headset()
        self.n85.click_usb_cable()
        self.n85.click_wired_headset()
        self.n85.click_black()
        self.n85.click_buy()
        self.settle_accounts_page.click_settle_accounts()
        self.log_in_to_buy_page.userinfo(user="root123456", password="root123456")
        self.add_page.click_add()
        self.submit_order.click_post()
        self.submit_order.click_balance()
        self.submit_order.click_boutique()
        self.submit_order.click_wish()
        self.submit_order.click_bill()
        self.submit_order.click_bill_type()
        self.submit_order.send_keys_remark("支付完成,尽快发货")
        self.submit_order.click_submit()
        self.finish_page.click_user()
        self.user_center.click_indent()
        reception_order_num = self.user_center.order_num()
        # 关闭前台浏览器
        self.home.quit(1)

        # 打开后台浏览器
        driver = get_driver()
        self.backstage_login = BackstageLogin(driver)
        self.backstage_home = BackstageHome(driver)
        # 访问后台网址
        self.backstage_login.get('http://localhost:8080/ecshop/admin/privilege.php?act=login')
        # 登录后台操作
        self.backstage_login.click_popup()
        self.backstage_login.click_ecseop()
        self.backstage_login.send_keys_username("root1234")
        self.backstage_login.send_keys_password("root1234")
        self.backstage_login.click_login()
        # 获取后台订单的订单号
        self.backstage_home.click_order_management()
        self.backstage_home.click_order_list()
        backstage_order_num = self.backstage_home.order_num()
        # 关闭后台浏览器
        self.backstage_login.quit(1)

        # 断言前台和后台生成的订单号是否一致
        self.assertEqual(reception_order_num, backstage_order_num, msg="前后台订单号不一致")

    @classmethod
    def tearDown(cls) -> None:
        # 关闭浏览器
        cls.home.quit()


if __name__ == '__main__':
    unittest.main(verbosity=2)
